package brickdestroyer;

import brickdestroyer.util.ImageResources;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

/**
 * @author Momchil Atanasov
 */
public class FrameDecorations {

    public static final int BORDER_TOP = 54;

    public static final int BORDER_BOTTOM = 20;

    public static final int BORDER_LEFT = 20;

    public static final int BORDER_RIGHT = 20;

    /*
     * This determines the X coordinate of the position where
     * game messages will be displayed.
     */
    private static final int GAME_MESSAGES_X = 40;

    /*
     * This determines the Y coordinate of the position where
     * game messages will be displayed.
     */
    private static final int GAME_MESSAGES_Y = 40;

    private static final String BACKGROUND_TOP_FILE = "background_top.jpg";

    private static final String BACKGROUND_BOTTOM_FILE = "background_bottom.jpg";

    private static final String BACKGROUND_LEFT_FILE = "background_left.jpg";

    private static final String BACKGROUND_RIGHT_FILE = "background_right.jpg";

    private final ImageRect topBorder;

    private final ImageRect bottomBorder;

    private final ImageRect leftBorder;

    private final ImageRect rightBorder;

    private String gameMessage = "Welcome to Momchil Atanasov's 'Brick Destroyer' Game!" +
            "  Press 'F1' for help.";

    public FrameDecorations(int width, int height) {
        topBorder = new ImageRect(0, 0, width, BORDER_TOP,
                ImageResources.getImage(BACKGROUND_TOP_FILE));
        bottomBorder = new ImageRect(0, height - BORDER_BOTTOM, width, BORDER_BOTTOM,
                ImageResources.getImage(BACKGROUND_BOTTOM_FILE));
        leftBorder = new ImageRect(0, BORDER_TOP, BORDER_LEFT, height - BORDER_BOTTOM - BORDER_TOP,
                ImageResources.getImage(BACKGROUND_LEFT_FILE));
        rightBorder = new ImageRect(width - BORDER_RIGHT, BORDER_TOP, BORDER_RIGHT,
                height - BORDER_BOTTOM - BORDER_TOP, ImageResources.getImage(BACKGROUND_RIGHT_FILE));
    }

    public void setGameMessage(String message) {
        gameMessage = message;
    }

    public void display(Graphics g) {
        topBorder.display(g);
        bottomBorder.display(g);
        leftBorder.display(g);
        rightBorder.display(g);
        displayGameMessage(g);
    }

    private void displayGameMessage(Graphics g) {
        g.setColor(Color.WHITE);
        g.drawString(gameMessage, GAME_MESSAGES_X, GAME_MESSAGES_Y);
    }

    private static class ImageRect {

        private final int x;

        private final int y;

        private final int width;

        private final int height;

        private final Image image;
        

        public ImageRect(int x, int y, int width, int height, Image image) {
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
            this.image = image;
        }

        public int getX() {
            return x;
        }

        public int getY() {
            return y;
        }

        public int getWidth() {
            return width;
        }

        public int getHeight() {
            return height;
        }

        public Image getImage() {
            return image;
        }

        public void display(Graphics g) {
            g.drawImage(image, x, y, width, height, null);
        }
    }


}
